From fe88c68919f1e12d726a34cad3ae9f114f93ab17 Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Tue, 22 Aug 2006 11:19:48 +0100 Subject: [PATCH] [XEN] Clean up some x86 bootstrap code. Replace some CPU iterators with for_each_cpu() -- we want to ensure that per_cpu areas are accessed only for cpus in cpu_possible_map. Signed-off-by: Keir Fraser --- xen/arch/x86/domain.c | 11 +++++++++-- xen/arch/x86/setup.c | 31 ++++++++++++++++++++----------- xen/arch/x86/smpboot.c | 2 -- xen/arch/x86/x86_32/mm.c | 8 +++++--- xen/arch/x86/x86_64/mm.c | 5 +++-- xen/common/sched_sedf.c | 11 ++--------- xen/common/schedule.c | 2 +- xen/common/timer.c | 2 +- xen/include/asm-x86/page.h | 3 ++- 9 files changed, 43 insertions(+), 32 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 38590f08f6..f2bb9a5920 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -125,8 +125,15 @@ struct vcpu *alloc_vcpu_struct(struct domain *d, unsigned int vcpu_id) v->arch.flags = TF_kernel_mode; - v->arch.schedule_tail = is_idle_domain(d) ? - continue_idle_domain : continue_nonidle_domain; + if ( is_idle_domain(d) ) + { + v->arch.schedule_tail = continue_idle_domain; + v->arch.cr3 = __pa(idle_pg_table); + } + else + { + v->arch.schedule_tail = continue_nonidle_domain; + } v->arch.ctxt_switch_from = paravirt_ctxt_switch_from; v->arch.ctxt_switch_to = paravirt_ctxt_switch_to; diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 01782320b3..2d77a506dc 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -190,10 +190,26 @@ static void percpu_free_unused_areas(void) __pa(__per_cpu_end)); } +static void init_idle_domain(void) +{ + struct domain *idle_domain; + + /* Domain creation requires that scheduler structures are initialised. */ + scheduler_init(); + + idle_domain = domain_create(IDLE_DOMAIN_ID); + if ( (idle_domain == NULL) || (alloc_vcpu(idle_domain, 0, 0) == NULL) ) + BUG(); + + set_current(idle_domain->vcpu[0]); + idle_vcpu[0] = this_cpu(curr_vcpu) = current; + + setup_idle_pagetable(); +} + void __init __start_xen(multiboot_info_t *mbi) { char __cmdline[] = "", *cmdline = __cmdline; - struct domain *idle_domain; unsigned long _initrd_start = 0, _initrd_len = 0; unsigned int initrdidx = 1; module_t *mod = (module_t *)__va(mbi->mods_addr); @@ -212,6 +228,7 @@ void __init __start_xen(multiboot_info_t *mbi) cmdline_parse(cmdline); set_current((struct vcpu *)0xfffff000); /* debug sanity */ + idle_vcpu[0] = current; set_processor_id(0); /* needed early, for smp_processor_id() */ smp_prepare_boot_cpu(); @@ -437,16 +454,6 @@ void __init __start_xen(multiboot_info_t *mbi) early_cpu_init(); - scheduler_init(); - - idle_domain = domain_create(IDLE_DOMAIN_ID); - if ( (idle_domain == NULL) || (alloc_vcpu(idle_domain, 0, 0) == NULL) ) - BUG(); - - set_current(idle_domain->vcpu[0]); - this_cpu(curr_vcpu) = idle_domain->vcpu[0]; - idle_vcpu[0] = current; - paging_init(); /* Unmap the first page of CPU0's stack. */ @@ -477,6 +484,8 @@ void __init __start_xen(multiboot_info_t *mbi) init_IRQ(); + init_idle_domain(); + trap_init(); timer_init(); diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index 734bd41797..39cbbd9282 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -896,8 +896,6 @@ static int __devinit do_boot_cpu(int apicid, int cpu) v = alloc_idle_vcpu(cpu); BUG_ON(v == NULL); - v->arch.cr3 = __pa(idle_pg_table); - /* start_eip had better be page-aligned! */ start_eip = setup_trampoline(); diff --git a/xen/arch/x86/x86_32/mm.c b/xen/arch/x86/x86_32/mm.c index dc2450201a..116228a53d 100644 --- a/xen/arch/x86/x86_32/mm.c +++ b/xen/arch/x86/x86_32/mm.c @@ -75,8 +75,6 @@ void __init paging_init(void) printk("PAE disabled.\n"); #endif - idle_vcpu[0]->arch.cr3 = __pa(idle_pg_table); - if ( cpu_has_pge ) { /* Suitable Xen mapping can be GLOBAL. */ @@ -120,8 +118,12 @@ void __init paging_init(void) idle_pg_table_l2[l2_linear_offset(IOREMAP_VIRT_START) + i] = l2e_from_page(virt_to_page(ioremap_pt), __PAGE_HYPERVISOR); } +} + +void __init setup_idle_pagetable(void) +{ + int i; - /* Install per-domain mappings for idle domain. */ for ( i = 0; i < PDPT_L2_ENTRIES; i++ ) idle_pg_table_l2[l2_linear_offset(PERDOMAIN_VIRT_START) + i] = l2e_from_page(virt_to_page(idle_vcpu[0]->domain-> diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index f173c05d83..279d54220c 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -81,8 +81,6 @@ void __init paging_init(void) l2_pgentry_t *l2_ro_mpt; struct page_info *pg; - idle_vcpu[0]->arch.cr3 = __pa(idle_pg_table); - /* Create user-accessible L2 directory to map the MPT for guests. */ l3_ro_mpt = alloc_xenheap_page(); clear_page(l3_ro_mpt); @@ -121,7 +119,10 @@ void __init paging_init(void) /* Set up linear page table mapping. */ idle_pg_table[l4_table_offset(LINEAR_PT_VIRT_START)] = l4e_from_paddr(__pa(idle_pg_table), __PAGE_HYPERVISOR); +} +void __init setup_idle_pagetable(void) +{ /* Install per-domain mappings for idle domain. */ idle_pg_table[l4_table_offset(PERDOMAIN_VIRT_START)] = l4e_from_page( diff --git a/xen/common/sched_sedf.c b/xen/common/sched_sedf.c index 4f7d6380e9..f8913703ac 100644 --- a/xen/common/sched_sedf.c +++ b/xen/common/sched_sedf.c @@ -1301,16 +1301,9 @@ static int sedf_adjust_weights(struct sched_adjdom_cmd *cmd) { struct vcpu *p; struct domain *d; - int sumw[NR_CPUS]; - s_time_t sumt[NR_CPUS]; - int cpu; + int sumw[NR_CPUS] = { 0 }; + s_time_t sumt[NR_CPUS] = { 0 }; - for ( cpu = 0; cpu < NR_CPUS; cpu++ ) - { - sumw[cpu] = 0; - sumt[cpu] = 0; - } - /* Sum across all weights. */ for_each_domain( d ) { diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 801966f38a..c65346d7fb 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -633,7 +633,7 @@ void __init scheduler_init(void) open_softirq(SCHEDULE_SOFTIRQ, __enter_scheduler); - for ( i = 0; i < NR_CPUS; i++ ) + for_each_cpu ( i ) { spin_lock_init(&per_cpu(schedule_data, i).schedule_lock); init_timer(&per_cpu(schedule_data, i).s_timer, s_timer_fn, NULL, i); diff --git a/xen/common/timer.c b/xen/common/timer.c index 8f2fa9964e..618906db38 100644 --- a/xen/common/timer.c +++ b/xen/common/timer.c @@ -382,7 +382,7 @@ void __init timer_init(void) SET_HEAP_SIZE(&dummy_heap, 0); SET_HEAP_LIMIT(&dummy_heap, 0); - for ( i = 0; i < NR_CPUS; i++ ) + for_each_cpu ( i ) { spin_lock_init(&per_cpu(timers, i).lock); per_cpu(timers, i).heap = &dummy_heap; diff --git a/xen/include/asm-x86/page.h b/xen/include/asm-x86/page.h index 94158c7f3d..01ab4be3c7 100644 --- a/xen/include/asm-x86/page.h +++ b/xen/include/asm-x86/page.h @@ -255,7 +255,8 @@ extern l2_pgentry_t idle_pg_table_l2[ROOT_PAGETABLE_ENTRIES*L2_PAGETABLE_ENTRI extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES]; extern l2_pgentry_t idle_pg_table_l2[ROOT_PAGETABLE_ENTRIES]; #endif -extern void paging_init(void); +void paging_init(void); +void setup_idle_pagetable(void); #endif #define __pge_off() \ -- 2.30.2